﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using CKFinder;

public partial class Admin_AddCatProduct : System.Web.UI.Page
{
    CategoryController categoryController = new CategoryController();
    protected void Page_Load(object sender, EventArgs e)
    {

        CKFinder.FileBrowser fb = new FileBrowser();
        fb.BasePath = "../ckfinder/";
        fb.SetupCKEditor(ckeditor);
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        Category c = new Category();
        c.Name = txtName.Text;
        c.Url = txtUrl.Text;
        c.Description = ckeditor.Text;
        c.Tag = txtTag.Text;
        c.Order = Convert.ToInt32(txtOrder.Text);
        if(ddlStatus.SelectedIndex==0)
        {
            c.Status = true;
        }
        else
        {
            c.Status = false;
        }
        c.DateStart = DateTime.Now;
        int id = categoryController.InsertShowID(c);
        if (id > 0)
        {
            if (catproduct_image_value.Value != "")
            {
                string str = catproduct_image_value.Value.Substring(1);
                char[] s = { ',' };
                string[] image = str.Split(s);
                foreach (var s1 in image)
                {
                    categoryController.InsertImageCat(id,s1,1,1,DateTime.Now);
                }
            }
            Response.Write("<script>alert('Thêm loại sản phẩm thành công')</script>");
            Server.Transfer(Request.RawUrl);
        }
        else
        {
            Response.Write("<script>alert('Thêm loại sản phẩm gặp lỗi')</script>");
        }
    }
}